package com.ecoolex.discount.sales.api.graphql;

import com.ecoolex.discount.sales.entity.DiscountBrandWithBLOBs;
import com.ecoolex.discount.sales.entity.MarketingBrand;
import com.ecoolex.discount.sales.pojo.QueryMarketingBrandDTO;
import com.ecoolex.discount.sales.ws.DiscountProductService;
import com.ecoolex.discount.sales.ws.MarketingProductService;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.lang.NonNull;

@GraphQL2Module(type = Type.User, description = "品牌营销")
public class MarketingBrandGraphql {

    @Reference
    private MarketingProductService marketingProductService;

    @Reference
    private DiscountProductService discountProductService;

    @TypeField(type = MarketingBrand.class, field = "discountBrand", description = "折扣品牌")
    public DiscountBrandWithBLOBs discountBrand(@Source MarketingBrand source) {
        return discountProductService.getDiscountBrand(source.getBrandId());
    }

    @QueryField(field = "marketingBrand", description = "品牌营销详情")
    public MarketingBrand get(@NonNull Integer id) {
        return marketingProductService.getMarketingBrand(id);
    }

    @QueryField(field = "marketingBrandList", description = "品牌营销列表")
    public Pagination<MarketingBrand> query(@NonNull QueryMarketingBrandDTO query, @NonNull Page page) {
        return marketingProductService.queryMarketingBrandForH5(query, page);
    }
}
